package com.babyqiao.wallpaper.common;

import io.swagger.annotations.ApiModelProperty;

import java.util.HashMap;
import java.util.Map;

/**
 * 统一结果返回类
 *
 * @author qinglongzhai
 */
public class UnifyResult {

    @ApiModelProperty("是否成功")
    private Boolean success;
    @ApiModelProperty("状态码")
    private Integer code;
    @ApiModelProperty("返回信息")
    private String message;
    @ApiModelProperty("返回数据")
    private Map<String, Object> data = new HashMap<>();

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }


    private UnifyResult() {
    }

    /**
     * 成功的静态方法
     */
    @ApiModelProperty("成功的返回结果")
    public static UnifyResult success() {
        UnifyResult unifyResult = new UnifyResult();
        unifyResult.setSuccess(true);
        unifyResult.setCode(ResultCode.SUCCESS);
        unifyResult.setMessage("成功");
        return unifyResult;
    }


    /**
     * 失败的方法
     */
    public static UnifyResult error() {
        UnifyResult unifyResult = new UnifyResult();
        unifyResult.setSuccess(false);
        unifyResult.setCode(ResultCode.ERROR);
        unifyResult.setMessage("失败");
        return unifyResult;
    }

    public UnifyResult success(Boolean success) {
        this.setSuccess(success);
        return this;
    }

    public UnifyResult message(String message) {
        this.setMessage(message);
        return this;
    }

    public UnifyResult code(Integer code) {
        this.setCode(code);
        return this;
    }

    public UnifyResult data(String key, Object value) {
        this.data.put(key, value);
        return this;
    }

    public UnifyResult data(Map<String, Object> map) {
        this.setData(map);
        return this;
    }


}
